<?php
require_once('Person.php');

class PersonProfile extends Person{
    	//protected $viewerPeId;
	protected $isFriend;
	protected $showButton;

	function __construct($peId, $viewerPeId){
	    	parent::__construct($peId, $viewerPeId);

		//$this->viewerPeId			= $viewerPeId;

		//add functions here:
		//$this->fetchFriendYesNo();
	}

	function fetchFriendYesNo(){
	    	$query1					= "SELECT * FROM Contacts WHERE OwnerPeId = '".$this->peId."' AND ContactPeId = '".$this->viewerPeId."';";
		//$query2 should also containc Approved = 1. Else you can just send a request to so and then see their full profile!
		$query2					= "SELECT * FROM Contacts WHERE OwnerPeId = '".$this->viewerPeId."' AND ContactPeId = '".$this->peId."' AND Approved = '1';";

		$exec1					= $this->db->query($query1);
		$exec2					= $this->db->query($query2);

		$row1					= $exec1->fetch_assoc();
		$row2					= $exec2->fetch_assoc();

		/*if ($row2['CoId'] == ""){
			$this->showButton		= true;
		} else {
		    	$this->showButton		= false;
		}*/

		if ($row2['CoId'] != "" || $row1['CoId'] != ""){
		    	$this->isFriend			= true;
		} else {
		    	$this->isFriend			= false;
		}
	}

	function fetchShowButton(){
	    $query					= "SELECT * FROM Contacts WHERE OwnerPeId = '".$this->viewerPeId."' AND ContactPeId = '".$this->peId."'";
	    //echo "<br />".$query."<br />";
	    $exec					= $this->db->query($query);
	    $returned_rows				= $exec->num_rows;
	    //echo $returned_rows."<br />";

	    if ($returned_rows == 0){
		$this->showButton			= true;
	    } else {
		$this->showButton			= false;
	    }
	}

	function arrangeData(){
	    	if ($this->isFriend == true){
		    	switch ($this->contactPrivacy){
			    	case 0:
					$this->dataDiv	= "<p>Nickname: ".$this->nickName."<br />
								email: ".$this->eMail;
					break;
				case 1:
				case 2:
				case 3:
					$this->dataDiv	= "<p>Nickname: ".$this->nickName."<br />
								Name: ".$this->name."<br />
								First Name: ".$this->firstName."<br />
								email: ".$this->eMail;
					break;
				case 4:
					$this->dataDiv	= "<p>Nickname: ".$this->nickName."<br />
								Name: ".$this->name."<br />
								First Name: ".$this->firstName."<br />
								email: ".$this->eMail."<br />
								Twitter: www.twitter.com/".$this->twitterName;
					break;
			}
		} else {
		    	switch ($this->generalPrivacy){
				case 0:
					$this->dataDiv	= "<p>NickName: ".$this->nickName."<br />
							    email: ".$this->eMail;
					break;
				case 1:
				case 2:
				case 3:
					$this->dataDiv	= "<p>NickName: ".$this->nickName."<br />
							    Name: ".$this->name."<br />
							    First name: ".$this->firstName."<br />
							    email: ".$this->eMail;
					break;
				case 4:
					$this->dataDiv	= "<p>NickName: ".$this->nickName."<br />
							    Name: ".$this->name."<br />
							    First name: ".$this->firstName."<br />
							    email: ".$this->eMail."<br />
							    Twitter: www.twitter.com/".$this->twitterName;
					break;
			}
		}
		if ($this->showButton == true){
			$this->dataDiv 		= $this->dataDiv."<form action=\"mycontacts.php\" method=\"post\">
							<input type=\"hidden\" name=\"PEID\" value=\"".$this->peId."\" />
							<input type=\"hidden\" name=\"addRemove\" value=\"add\" />
							<input type=\"submit\" value=\"Add Contact\" />
							</form>
							</p>";
		} else {
			$this->dataDiv 		= $this->dataDiv."<form action=\"mycontacts.php\" method=\"post\">
							<input type=\"hidden\" name=\"PEID\" value=\"".$this->peId."\" />
							<input type=\"hidden\" name=\"addRemove\" value=\"remove\" />
							<input type=\"submit\" value=\"Remove Contact\" />
							</form>
							</p>";
		}

	}
	
	// Getter and Setter
	public function getIsFriend(){
	    	return $this->isFriend;
	}
	public function getShowButton(){
	    	return $this->showButton;
	}
	public function getDataDiv(){
	    	return $this->dataDiv;
	}
}
?>
